package com.partition.mysql.handle;


import com.partition.mysql.bean.PartitionItem;
import com.partition.mysql.em.RangeStrategyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ClassName: CompositePartitionHandler <br/>
 * Description: 分区处理对象 <br/>
 * Date: 2022/4/11 16:25 <br/>
 *
 * @author hexinglin
 * @version 1.0.0
 * @since 1.8
 */

@Component
public class CompositePartitionHandler {


    /**
     * 天处理对象
     */
    @Autowired
    private PartitionByDayHandler partitionByDayHandler;

    /**
     * 月处理对象
     */
    @Autowired
    private PartitionByMonthHandler partitionByMonthHandler;

    /**
     * 年处理对象
     */
    @Autowired
    private PartitionByYearHandler partitionByYearHandler;


    /**
     * 对表分区
     *
     * @param item
     * @return
     */
    public void partition(PartitionItem item, RangeStrategyEnum type) {
        switch (type){
            case DAY:
                partitionByDayHandler.partition(item);
                break;
            case MONTH:
                partitionByMonthHandler.partition(item);
                break;
            case YEAR:
                partitionByYearHandler.partition(item);
                break;
            default :
                partitionByMonthHandler.partition(item);
        }
    }

    /**
     * 定时任务处理表分区
     *
     * @param item
     * @return
     */
    public void partitionJob(PartitionItem item, RangeStrategyEnum type) {

        switch (type){
            case DAY:
                partitionByDayHandler.partitionJob(item);
                break;
            case MONTH:
                partitionByMonthHandler.partitionJob(item);
                break;
            case YEAR:
                partitionByYearHandler.partitionJob(item);
                break;
            default :
                partitionByMonthHandler.partitionJob(item);
        }
    }
}
